//
//  LTQRetweetView.swift
//  WeiBoProject
//
//  Created by MAC on 16/3/2.
//  Copyright © 2016年 LTQ. All rights reserved.
//

import UIKit
import SnapKit
class LTQRetweetView: UIView {
    
    var bottomConstraint: Constraint?
    
    var retweetViewModel:LTQStatusViewModel?{
        didSet{
            contentLabel.text = retweetViewModel?.retweetStatusString
//            判断，如果有转发的配图则显示转发配图
//            没有则不进行显示
            
//            转发微博的图片都在转发微博的字段中
            self.bottomConstraint?.uninstall()
            
           if let pic_url = retweetViewModel?.statusModel?.retweeted_status?.pic_urls where pic_url.count > 0{
            
                pictureView.hidden = false
            self.snp_updateConstraints(closure: { (make) -> Void in
                
              self.bottomConstraint = make.bottom.equalTo(pictureView.snp_bottom).constraint
            })
            
            var nmArray = [LTQPictureViewModel]()
            for model in pic_url{
                let viewModel = LTQPictureViewModel()
                viewModel.model = model
                nmArray.append(viewModel)
            }
            pictureView.pictureList = nmArray
            
           }else{
            
            pictureView.hidden = true
            
            self.snp_updateConstraints(closure: { (make) -> Void in
              self.bottomConstraint = make.bottom.equalTo(contentLabel.snp_bottom).constraint
            
            })
            
            }
            
            
        }
    }
    
   override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
   required init?(coder aDecoder: NSCoder) {
       fatalError("init(coder:) has not been implemented")
    }
    func setupUI(){
        
        addSubview(contentLabel)
        addSubview(pictureView)
        
        backgroundColor = UIColor(red: 243.0/255.0, green: 243.0/255.0, blue: 244.0/255.0, alpha: 1.0)
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(CellMargin)
            make.top.equalTo(self.snp_top)
            make.width.equalTo(UIScreen.mainScreen().bounds.width - 2 * CGFloat(CellMargin))
            
        }
//        先默认都拥有配图
        pictureView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(CellMargin)
            make.top.equalTo(contentLabel.snp_bottom)
            
        }
        
    }
    
    private lazy var contentLabel: UILabel = {
       
        let label = UILabel()
        label.text = "转发微博"
        label.font = UIFont.systemFontOfSize(14)
        label.numberOfLines = 0
        
        return label
    }()
    private lazy var pictureView: LTQPictureView = LTQPictureView()

}
